#include <iostream>
#include <utility>
#include <cstring>

class MyString {
public:
    MyString(const char* str) {
        size = strlen(str);
        data = new char[size + 1];
        strcpy(data, str);
    }

    // 移动构造函数
    MyString(MyString&& other) noexcept {
        data = other.data;
        size = other.size;
        other.data = nullptr;
        other.size = 0;
    }

    ~MyString() {
        //new的数据就是麻烦，害的自己delete
        delete[] data;
    }

    const char* c_str() const {
        return data;
    }

private:
    char* data;
    size_t size;
};

int main() {
    MyString str1("Hello");
    MyString str2(std::move(str1));

    // std::cout << "str1: " << str1.c_str() << std::endl; // 用这个定义输出会有问题，
    std::cout << "str1: " << (str1.c_str() ? str1.c_str() : "nullptr") << std::endl;
    std::cout << "str2: " << str2.c_str() << std::endl; // 输出 "Hello"

    return 0;
}